const baseUrl = "http://47.108.197.28:";

function http(url){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseUrl + url,
      header: {"content-type":"application"},
      method: "GET",
      dataType: "json",
      responseType: "text",
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      },
    })
  })
}

function handleStar(num){
  var res = [];
  for(var i = 0 ; i < 5 ; i++){
    if(num>=2){
        res.push(2);
    }else if(num>0){
        res.push(parseFloat(num.toFixed(1)));
    }else{
        res.push(0);
    }
    num -= 2;
  }
  return res;
}

function getMusicHttp(){
  return http("3000/top/playlist/highquality");
}

function getBookHttp(){
  return http("8000/book");
}

function getMovieTop250Http(){
  return http("4000/api/movie/top250");
}

function getMovieInTheatersHttp(){
  return http("4000/api/movie/inTheaters");
}

function getMovieComingSoonHttp(){
  return http("4000/api/movie/comingSoon");
}
module.exports = {
  http,
  handleStar,
  getMusicHttp,
  getBookHttp,
  getMovieTop250Http,
  getMovieInTheatersHttp,
  getMovieComingSoonHttp
}